package main

import (
	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/services"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 通知消息解析示例
func msgNotifyDemo(clearingService *services.ClearingService) {
	// 构建通知数据
	notifyData := map[string]interface{}{
		"merch_no":      "84944035812S123",
		"settle_type":   "T0",
		"amount":        "2000",
		"fee_amount":    "300",
		"out_settle_id": "191912345678901894",
		"settle_id":     "411109630795649800601630",
		"postscript":    "postscript",
		"payment_time":  "2024-02-21 14:50:22",
		"org_no":        "123456",
		"result_state":  "SUCCESS",
	}

	// 解析通知消息
	notifyDto := clearingService.ParseNotify(notifyData)

	utils.Infof("通知消息解析成功！")
	utils.Infof("商户号：%s", notifyDto.MerchNo)
	utils.Infof("结算类型：%s", notifyDto.SettleType)
	utils.Infof("金额：%s", notifyDto.Amount)
	utils.Infof("手续费：%s", notifyDto.FeeAmount)
	utils.Infof("外部结算ID：%s", notifyDto.OutSettleID)
	utils.Infof("结算ID：%s", notifyDto.SettleID)
	utils.Infof("附言：%s", notifyDto.Postscript)
	utils.Infof("付款时间：%s", notifyDto.PaymentTime)
	utils.Infof("机构号：%s", notifyDto.OrgNo)
	utils.Infof("结果状态：%s", notifyDto.ResultState)
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 通知消息解析示例 开始 =====")
	utils.Info("=============================")

	// 创建配置对象和清算服务
	config := demo.CreateDemoConfig()
	clearingService := services.NewClearingService(config)

	msgNotifyDemo(clearingService)

	utils.Info("=============================")
	utils.Info("===== 通知消息解析示例执行完毕 =====")
	utils.Info("=============================")
}
